﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace JalaliCalendar
{
    public sealed partial class YearControl : UserControl
    {
        public YearControl(int year, int offset)
        {
            this.InitializeComponent();

            YearTextBlock.Text = Tasks.DateConvertorBackgroundTask.ConvertNumerals(year.ToString());

            int[][] days = new int[4][];
            days[0] = new int[] { 31, 31, 31 };
            days[1] = new int[] { 31, 31, 31 };
            days[2] = new int[] { 30, 30, 30 };
            days[3] = new int[] { 30, 30, 29 };

            if (Tasks.CalendarConversion.IranianIsLeap(year))
                days[3][2]++;

            for (int ii = 0; ii < 4; ii++)
            {
                SeasonControl sc = new SeasonControl(year, ii, offset, days[ii]);
                Grid.SetRow(sc, 1);
                Grid.SetColumn(sc, ii);
                MainGrid.Children.Add(sc);
                for (int jj = 0; jj < 3; jj++)
                    offset += days[ii][jj];
                offset %= 7;
            }
        }
    }
}
